import { NextFunction, Request, Response } from "express";
import HttpException from "../exception/http.ex";

function errorMiddleware(
  error: HttpException,
  request: Request,
  response: Response,
  next: NextFunction
) {
  const status = error.status || 500;
  const message = error.message || "服务器发生了内部错误";
  console.log(error);
  console.log("错误处理器（mw）被激活了");

  response.status(status).send({
    status,
    message,
  });
  return;
}

export default errorMiddleware;
